var model = {
	curcomponent: 'title',
	init: function() {},
	initEditor: function() {},
	initItem:function () {}
}

model.init = function() {
	$("#content").sortable({
		placeholder: "portlet-placeholder",
		revert: 100,
		scroll: false,
		start: function(event, ui) {
			var height = ui.item.height();
			$(".portlet-placeholder").css({
				"height": height + "px",
			});
			$(".portlet-placeholder").html('<div><i class="fa fa-plus"></i> 放置此处</div>');
			$(".portlet-placeholder div").css({
				"line-height": height - 4 + "px"
			})
		},
		update:function(event, ui){

		}
	});
	$("#content").disableSelection();

	$('.component_btn').unbind('click').bind('click', function() {
		var component = $(this).data('value');
		var component_div = $('div[data-component="'+component+'"]').html();
		var component_edit = $('#'+component+'Editor').html();
		model.curcomponent = component;
		$('#content').append(component_div);
		$('#componenteditor').empty();
		$('#componenteditor').append(component_edit);
		$('#content').find('.drag').removeClass('selected');
		$('#content').find('.drag').last().addClass('selected');
		var margin_top = $('.selected').offset().top;
		$('#componenteditor').css('margin-top',margin_top-120);
		model.initItem();
	});
}
model.initItem = function () {
	$('.drag').bind('mouseup',{},function () {
		$('.drag').removeClass('selected');
		$(this).addClass('selected');
		var margin_top = $('.selected').offset().top;
		$('#componenteditor').css('margin-top',margin_top-120);
	});
}
model.init();